package com.mc.web.controller.fil;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mc.common.annotation.Log;
import com.mc.common.core.controller.BaseController;
import com.mc.common.core.domain.AjaxResult;
import com.mc.common.enums.BusinessType;
import com.mc.fil.domain.FilPlantInfo;
import com.mc.fil.service.IFilPlantInfoService;
import com.mc.common.utils.poi.ExcelUtil;
import com.mc.common.core.page.TableDataInfo;

/**
 * 种植信息 Controller
 *
 * @author mc
 * @date 2021-04-13
 */
@RestController
@RequestMapping("/fil/info")
public class FilPlantInfoController extends BaseController
{
    @Autowired
    private IFilPlantInfoService filPlantInfoService;

    /**
     * 查询种植信息 列表
     */
    @PreAuthorize("@ss.hasPermi('fil:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(FilPlantInfo filPlantInfo)
    {
        startPage();
        List<FilPlantInfo> list = filPlantInfoService.selectFilPlantInfoList(filPlantInfo);
        return getDataTable(list);
    }

    /**
     * 导出种植信息 列表
     */
    @PreAuthorize("@ss.hasPermi('fil:info:export')")
    @Log(title = "种植信息 ", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FilPlantInfo filPlantInfo)
    {
        List<FilPlantInfo> list = filPlantInfoService.selectFilPlantInfoList(filPlantInfo);
        ExcelUtil<FilPlantInfo> util = new ExcelUtil<FilPlantInfo>(FilPlantInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取种植信息 详细信息
     */
    @PreAuthorize("@ss.hasPermi('fil:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(filPlantInfoService.selectFilPlantInfoById(id));
    }

    /**
     * 新增种植信息
     */
    @PreAuthorize("@ss.hasPermi('fil:info:add')")
    @Log(title = "种植信息 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FilPlantInfo filPlantInfo)
    {
        return toAjax(filPlantInfoService.insertFilPlantInfo(filPlantInfo));
    }

    /**
     * 修改种植信息
     */
    @PreAuthorize("@ss.hasPermi('fil:info:edit')")
    @Log(title = "种植信息 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FilPlantInfo filPlantInfo)
    {
        return toAjax(filPlantInfoService.updateFilPlantInfo(filPlantInfo));
    }

    /**
     * 修改种植信息
     */
    @PreAuthorize("@ss.hasPermi('fil:info:edit')")
    @Log(title = "种植信息 ", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody FilPlantInfo filPlantInfo)
    {
        FilPlantInfo plantInfo = new FilPlantInfo();
        plantInfo.setId(filPlantInfo.getId());
        plantInfo.setRateSurvival(filPlantInfo.getRateSurvival());
        plantInfo.setGreenRate(filPlantInfo.getGreenRate());
        return toAjax(filPlantInfoService.updateFilPlantInfoForRateSurvivalAndGreenRate(plantInfo));
    }

    /**
     * 删除种植信息
     */
    @PreAuthorize("@ss.hasPermi('fil:info:remove')")
    @Log(title = "种植信息 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(filPlantInfoService.deleteFilPlantInfoById(id));
    }
}